#include<bits/stdc++.h>
using namespace std;

int n, L;
vector<vector<int> > userlist;

int query(int id, int l) {
	vector<int> visit(n + 10, 0), que(100*n);
	int front = 0, rear = 0, p = 0;
	int re = -1;
	que[front++] = id;
	p = front;

	while (l >= 0 && front != rear) {
		int v = que[rear++];
		if (!visit[v]) {
			visit[v] = 1;
			re++;
			for (auto it = userlist[v].begin(); it != userlist[v].end(); it++) {
				int vv = *it;
				if (!visit[vv]) {
					que[front++] = vv;
				}
			}
		}
		if (rear == p) {
			l--;
			p = front;
		}
	}
	return re;
}

int main() {
	scanf("%d %d", &n, &L);
	userlist.resize(n + 1);
	for (int i = 1; i <= n; i++) {
		int m;
		scanf("%d", &m);
		for (int j = 0; j < m; j++) {
			int userid;
			scanf("%d", &userid);
			userlist[userid].push_back(i);
		}
	}

	int m;
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		int id;
		scanf("%d", &id);
		int re = query(id, L);
		printf("%d\n", re);
	}
	return 0;
}